import numpy as np
np.set_printoptions(suppress=True)

input_example = [[-0.803556, 1.803556, 0.016222, 0.0, 0.0, 0.004444, 0.000444, 0.052444, 0.097556, 8450139.022222, 0.131081, 0.004413, 0.072321, 0.868919, 0.00305, 0.004159, 1209008640.0, 478536192.0, 31802.4, 32218.6, 22029476.5, 8450139.022222],
[-0.891333, 1.891333, 0.035778, 0.0, 0.0, 0.0, 0.0, 0.027556, 0.034444, 198337.422222, 0.076584, 0.003422, 0.047097, 0.923416, 0.005257, 0.003815, 598827520.0, 925864448.0, 2583.266667, 3061.8, 3030607.5, 198337.422222],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5677448.647111, 0.07524, 0.0034, 0.047145, 0.92476, 0.005285, 0.003765, 604049920.0, 923632128.0, -1, -1, 3011592.0, 5677448.647111],
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 16791924736.0, 0.146394, 0.006558, 0.087674, 0.853606, 0.003772, 0.004642, 1381130752.0, 1922301952.0, -1, -1, 22523937.0, 16791924736.0]]

output_example = [[0.09847835, 0.95358988, 0.45340712, float('nan'), float('nan'), 1.,
  1., 1., 1., 0.00049142, 0.78479074, 0.32077264,
  0.62163294, 0.21520926, 0., 0.44925884, 0.77998031, 0.,
  1., 1., 0.97465909, 0.00049142],
 [0., 1., 1., float('nan'), float('nan'), 0.,
  0., 0.52543666, 0.35306901, 0., 0.01888861, 0.00696643,
  0., 0.98111139, 0.98747204, 0.05701254, 0., 0.30983437,
  0.08125756, 0.09506015, 0.00097454, 0.],
 [1., 0., 0., float('nan'), float('nan'), 0.,
  0., 0., 0., 0.0003263,  0., 0.,
  0.00118294, 1., 1., 0., 0.00667567, 0.30828819,
  0., 0., 0., 0.0003263],
 [1., 0., 0., float('nan'), float('nan'), 0.,
  0., 0., 0., 1., 1., 1.,
  1., 0., 0.32304251, 1., 1., 1.,
  0., 0., 1., 1.]]


def compare(o_e, o):
    assert isinstance(o_e, np.ndarray)
    assert isinstance(o, np.ndarray)

    if o_e.shape == o.shape:
        for i in range(0, o_e.shape[0]):
            for j in range(0, o_e.shape[1]):
                if np.isnan(o_e[i, j]):
                    pass
                else:
                    if round(float(o[i, j]), 8) != o_e[i, j]:
                        print(o[i, j])
                        print(o_e[i, j])
                        print(str(i) + "-" + str(j))
                        return False
        return True
    else:
        return False


def ourpreprocess(temp_arr):
    no=temp_arr.shape[1]
    DSIZE=temp_arr.shape[0]
    for num in range(0,no):
        value=temp_arr[:,num]
        npArray=dataPreprocess(value,DSIZE)
        temp_arr[:, num]=npArray
    return temp_arr

def dataPreprocess(npArray,DSIZE):
    # min-max标准化   离差标准化，是对原始数据的线性变换，使结果值映射到[0 - 1]之间
    npArray = [(x - min(npArray)) / (max(npArray) - min(npArray)) for x in npArray]
    return npArray

# 用例目的
print("该用例目的为：")
print("进行数据标准化处理组件功能测试，测试组件在正常输入下能否获得正确结果，矩阵各位置数值在[0-1]范围内")

# 子用例编号
print("子用例编号：")
print("Standardization_1")

print("****************************")
print("当前输入为：")
# 输出用例设置
print(input_example)
# 输出用例设置

print("")

print("****************************")
print("当前输出为:")
# 输出处理后数据
output = ourpreprocess(np.array(input_example))
print(output)
# 输出处理后数据

print("****************************")
print("是否正确:")
# 输出对比结果
# 需要写一个compare函数
if compare(np.array(output_example), output):
    print("输出与预定目标相符")
else:
    print("输出与预定目标不符")
# 输出对比结果

print("\n")
